#define _CRT_SECURE_NO_WARNINGS 1
int TreeSize(struct TreeNode* root) {
    if (!root) {
        return 0;
    }
    return 1 + TreeSize(root->left) + TreeSize(root->right);
}
void preorder(struct TreeNode* root, int* a, int* i) {
    if (root == NULL) {
        return;
    }
    a[*i] = root->val;
    (*i)++;
    preorder(root->left, a, i);
    preorder(root->right, a, i);

}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int size = TreeSize(root);
    int* a = (int*)malloc(sizeof(int) * size);
    int i = 0;
    preorder(root, a, &i);
    *returnSize = size;
    return a;
}